<?php
/**
 * Created by PhpStorm.
 * User: zzw
 * Date: 17-3-16
 * Time: 下午4:44
 */
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Collects_model extends MY_Model
{
    protected $table = 'collects';
    //添加收藏--长文章
    public function create_long($data) {
        $query = $this->db
            ->select('id')
            ->from('long_article')
            ->where('id', $data['tid'])
            ->get();
        if ($this->db->affected_rows()) {
            $re = $query->row_array();
            if($re) {
                $this->db->insert($this->table, $data);
                if ($this->db->affected_rows()) {
                    $id = $this->db->insert_id();
                    $this->db->set('collects', 'collects + 1',false)
                        ->where(array('id' => $data['tid']))
                        ->update('long_article');
                    $this->db->affected_rows();
                    return $id;
                }
            }
        }
        return 0;
    }
    public function set($id, $arr) {
        $this->db->set($arr)
            ->where(array('id' => $id))
            ->update($this->table);
        return $this->db->affected_rows();
    }
    public function get_list_long($limit=5,$start=0,$order=false,$where=false,$fields="*",$table=FALSE,$join=false){
        $this->db->select($fields)
            ->from($this->table)

            ->join('long_article', 'long_article.id=collects.tid')
            ->join('account', 'account.id=long_article.uid', 'left')
            ->where($where)
            ->order_by($order)
            ->limit($limit, $start);
        $query = $this->db->get();
        return $query->result_array();
    }
}